<template>
  <div class="alipay">
    <span>{{ msg }}</span>
    <img @click="backforward" src="../assets/image/btn.png" alt="" />
  </div>
</template>

<script>
import { alipayBindAlipay } from "../api/reply";

export default {
  data() {
    return {
      msg: "",
    };
  },
  methods: {
    alipayBindAlipay() {
      window.localStorage.setItem("access_token", this.$route.query.token);
      if (this.$route.query.userId == undefined) {
        this.msg = "授权失败";
      } else {
        alipayBindAlipay({
          alipayUserId: this.$route.query.userId,
        }).then((res) => {
          if (res.code == 0) {
            this.msg = "授权成功";
          }
        });
      }
    },
    backforward() {
      let that = this;
      var u = navigator.userAgent;
      var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android终端
      var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
      //判断手机：是Ios终端还是android终端
      if (isAndroid) {
        window.quotationSystem.htmlBack();
      } else if (isiOS) {
        //Toast("IOS")
        window.location.href = "https://ios.outsea.psychexy.com/outsea";
        // this.$bridge.callhandler("htmlBack", "", (data) => {
        //   // 处理返回数据
        //   //Toast(data);
        //   console.log(111);
        // });
      } else {
        this.$toast("返回操作失败");
      }
    },
  },
  created() {
    this.alipayBindAlipay();
  },
};
</script>

<style lang="less" scoped>
.alipay {
  background: url("../assets/image/shouquan.png") no-repeat 50% 30%;
  background-size: 50%;
  width: 100%;
  height: 100%;
  span {
    position: absolute;
    top: 40%;
    left: 42%;
    font-size: 15px;
    color: black;
  }
  img {
    position: absolute;
    top: 50%;
    left: 26%;
    width: 50%;
  }
}
</style>